//
//  LLSQLiteManager.swift
//  WeiBoShiBing
//
//  Created by Bingo on 15/11/13.
//  Copyright © 2015年 Bingo. All rights reserved.
//

import UIKit

class LLSQliteManager:NSObject{

    static let sharedManager = LLSQliteManager()
    
    private let dbName = "status.db"
    
    let dbQuere:FMDatabaseQueue
    
    
    override init() {
        
        let documentPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last!
        
        let dbPath = (documentPath as NSString).stringByAppendingPathComponent(dbName)
        
        dbQuere = FMDatabaseQueue(path: dbPath)
        
        super.init()
        
        createTabel("T_Person")
        
    }
    
    
    
    func createTabel(tbName:String){
    
        let path = NSBundle.mainBundle().pathForResource("tables", ofType: "sql")!
        
        let sqls = try! String(contentsOfFile: path)
        
        dbQuere.inDatabase { (db) -> Void in
            
            if db.executeStatements(sqls){
                
                print("执行数据表格成功")
            }else{
                print("创建数据表格失败")
            }
        }
    
    }
}
